﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using xTeam.HengLe.DataAccess;
using xTeam.HengLe.Entity;
using System.ComponentModel;
using xTeam.Hengle.DataAccess;
namespace xTeam.HengLe.Controller.Manage
{
    public class NewsController : BaseController
    {
      
        /// <summary>
        /// 首页
        /// </summary>
        public ActionResult Index()
        {
            return RedirectToAction("List");
        }
        /// <summary>
        /// 检索新闻
        /// </summary>
        public ActionResult List(
            string key = ""
            , int classifyid = 0)
        {
            NewsViewModel viewModel = new NewsViewModel();
            viewModel.NewsList = _newsDataAccess.Search(key, classifyid, null);
            viewModel.ClassifyList = _classifyDataAccess.GetClassLisytByModuleKey("News");
            return View(viewModel);
        }
        /// <summary>
        /// 根据新闻编号获取新闻
        /// </summary>
        public ActionResult Edit([DefaultValue(0)]int newsId)
        {
            NewsViewModel viewModel = new NewsViewModel();
            viewModel.NewsInfo = _newsDataAccess.GetNewsById(newsId, null) ?? new ENews() { Isvalid = true, WriteTime = DateTime.Now };
            viewModel.ClassifyList = _classifyDataAccess.GetClassLisytByModuleKey("News");
            return View(viewModel);
        }
        /// <summary>
        /// 添加修改新闻
        /// </summary>
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Edit(ENews news)
        {
            int ret = _newsDataAccess.Edit(news);
            return RedirectToAction("Edit", new { newsId = ret });
        }
        /// <summary>
        /// 删除新闻
        /// </summary>
        [HttpPost]
        public ActionResult Delete(int newsId)
        {
            // 执行新闻删除
            int ret = _newsDataAccess.Delete(newsId);
            return new EmptyResult();
        }
    }
}
